//
//  ChoosePatternViewController.m
//  RONGAO
//
//  Created by wei wang on 2017/9/25.
//  Copyright © 2017年 wei wang. All rights reserved.
//

#import "ChoosePatternViewController.h"

@interface ChoosePatternViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
/** <#Description#> **/
@property(nonatomic,strong) NSArray *titlesArr;

/** <#Description#> **/
@property(nonatomic,copy) NSString *chooseFlag;

@end

static NSString *const CellIdentifier = @"CellIdentifier";
static NSString *const selectPattern = @"selectPattern";
@implementation ChoosePatternViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.titlesArr = @[@"离家模式",@"回家模式",@"普通模式"];
    
    [self setNavigationStyle];
    
    self.tableView.tableFooterView = [UIView new];
    
    self.chooseFlag = EXRACT_OBJECT(selectPattern) ? EXRACT_OBJECT(selectPattern) : self.titlesArr.lastObject;
    
}

- (void)setNavigationStyle{
    [self setNavigationTitle:@"模式选择" titleColor:nil];
    [self setLeftButtonImage:[UIImage imageNamed:@"icon_back_nor"]];
}

- (void)onLeftButtonClick:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - tableview DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _titlesArr.count;
}

#pragma mark - tableview Delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 56;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        [cell.textLabel setFont:[UIFont systemFontOfSize:15]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.detailTextLabel.textColor = [UIColor darkGrayColor];
    }
    cell.textLabel.text  = self.titlesArr[indexPath.row];
    cell.detailTextLabel.text = @"具体提示语视设备添加齐全确定";
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.accessoryView = ([self.titlesArr indexOfObject:self.chooseFlag] == indexPath.row) ? [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"video_set_bg_sel"]] : [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"video_set_bg_nor"]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.chooseFlag = self.titlesArr[indexPath.row];
    SAVE_OBJECT(self.chooseFlag, selectPattern);
    [self.tableView reloadData];
}



@end
